#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "Globales.h"

void strcpyMem(char* szDestino[], const char* szCadena) {
  int iLen = 0;
  int iCadenaNula = 0;
  iCadenaNula = strcmp(szCadena, "");
  iLen = strlen(szCadena);
  if (&szDestino != NULL) {
    free(&szDestino);
  }
  if (iCadenaNula != 0) {
    *szDestino = (char*)malloc((iLen * sizeof(char)) + 1);
    strcpy(*szDestino, szCadena);
  } else {
    *szDestino = NULL;
  }
}

void strcat2Mem(char* acCadena[], char c) {
  int iLen = 0;
  char acChar[2];
  acChar[0] = c;
  acChar[1] = '\0';
  char* szAux;
  if (*acCadena == NULL) {
    iLen = 0;
    *acCadena = (char*)malloc(sizeof(char) + 1);
    strcpy(*acCadena, acChar);
  } else {
    iLen = strlen(*acCadena);
    szAux = (char*)malloc((sizeof(char) * iLen) + 2);
    strcpy(szAux, *acCadena);
    free(*acCadena);
    *acCadena = szAux;
    strcat(*acCadena, acChar);
  }
}
